<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="tld" uri="/WEB-INF/tld/rei.tld" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@include file="/WEB-INF/include/admin-head.jsp" %>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">




        <div class="layui-form-item">
            <label class="layui-form-label">保单号</label>
            <div class="layui-input-block">
                <input type="text" name="ordersId" placeholder="请输入保单" autocomplete="off" class="layui-input"
                       value="${model.id}" lay-verify="required">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">交警定责</label>
            <div class="layui-input-block">
                <textarea name="responsibility" placeholder="请输入交警定责" class="layui-textarea"></textarea>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">车损情况</label>
            <div class="layui-input-block">
                <textarea name="car" placeholder="请输入车损情况" class="layui-textarea"></textarea>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">伤亡情况</label>

            <div class="layui-input-block">
                <textarea name="casualties" placeholder="请输入伤亡情况" class="layui-textarea"></textarea>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">情况属实</label>

            <div class="layui-input-block">
                <textarea name="reals" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">现场照片</label>
            <div class="layui-input-inline">
                <img src="" name="image" width="80px;">
                <input name="image" value="" type="hidden"/>
            </div>
            <div class="layui-input-inline layui-btn-container" style="width: auto;">
                <button type="button" class="layui-btn layui-btn-primary" id="upload">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>

            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" type="button" lay-submit lay-filter="add">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script src="/static/lib/layui/layui.js"></script>
<script src="/static/js/jquery.min.js"></script>
<script>
    layui.use(["element", "form", "laydate", "okLayer", "okUtils"], function () {
        let form = layui.form;
        let laydate = layui.laydate;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
        okLoading.close();


        form.verify({
            time: [/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))(\s(([01]\d{1})|(2[0123])):([0-5]\d):([0-5]\d))?$/, '日期格式不正确']
        });

        form.on("submit(add)", function (data) {
            $.post("/admin/responsibility/save", data.field, function (result) {
                if (result.code == 0) {
                    layer.alert("成功", {icon: 6}, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                        window.parent.location.reload();//刷新父页面
                    });
                } else {
                    layer.alert("失败", {icon: 5});
                }
            })
        });

        //上传
        layui.use('upload', function () {
            var upload = layui.upload;
            //执行实例
            var uploadInst = upload.render({
                elem: '#upload' //绑定元素
                , url: '/files/upload' //上传接口
                , done: function (res) {
                    //上传完毕回调
                    $("img[name=image]").attr("src", "/admin/attachment/image/"+res.data.id);
                    $("input[name=image]").val(res.data.id);
                }
                , error: function () {
                    //请求异常回调
                    layer.alert("上传失败", {icon: 5});
                }
            });
        });
    });
</script>
</body>
</html>


